home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / misc / elcheapofax.lha / printers / render.c < prev    next >
C/C++ Source or Header  |  1993-04-15  |  4KB  |  168 lines

  1.  
  2. /*
  3.  *  RENDER.C
  4.  *
  5.  *  David Berezowski - March/88.
  6.  *  Modified for DICE - May/91    Matthew Dillon
  7.  *  Modified for ElCheapoFax April 1993 Olaf 'Rhialto' Seibert.
  8.  *
  9.  *  Copyright (c) 1988  Commodore-Amiga, Inc.
  10.  *  (c)Copyright 1991 Matthew Dillon
  11.  *  (c)Copyright 1993 Olaf Seibert
  12.  */
  13.  
  14. #include <string.h>
  15. #include "defs.h"
  16.  
  17. Prototype __geta4 long Render(long, long, long, long);
  18. Prototype void Transfer(PrtInfo *, UWORD, UBYTE *);
  19. Prototype void *OpenFaxFile(void);
  20.  
  21. int NoFormFeed;
  22.  
  23. /*__geta4*/ long
  24. Render(ct, x, y, status)
  25. long ct, x, y, status;
  26. {
  27.     static long LineBufSize, TotalBufSize;
  28.     static void *FaxHandle;
  29.     static int XSize;
  30.  
  31.     long err;
  32.  
  33.     err = PDERR_NOERR;
  34.  
  35.     /*debug(("Render ct %08lx x %d y %d status %d\n", ct, x, y, status));*/
  36.     switch(status) {
  37.     case 5: /* Pre-Master Initialization */
  38.     /*
  39.      *    ct    - 0 or pointer to IODRPReq structure.
  40.      *    x    - io_Special flag from IODRPReq.
  41.      *    y    - 0.
  42.      */
  43.     debug(("Pre-master init\n"));
  44.     /* select density */
  45.     SetDensity(x & SPECIAL_DENSITYMASK);
  46.     PED->ped_NumRows = 16;
  47.     break;
  48.     case 0:    /* Master Initialization */
  49.     /*
  50.      *    ct    - pointer to IODRPReq structure.
  51.      *    x    - width of printed picture in pixels.
  52.      *    y    - height of printed picture in pixels.
  53.      */
  54.     debug(("Master init\n"));
  55.     XSize = x;
  56.     if (XSize != LINE_BITS) {
  57.         XSize = LINE_BITS;
  58.         debug(("XSize adjusted from %d to %d\n", x, XSize));
  59.     }
  60.     NoFormFeed = (((struct IODRPReq *)ct)->io_Special & SPECIAL_NOFORMFEED)
  61.              != 0;
  62.     PD->pd_PrintBuf = NULL;
  63.     if ((FaxHandle = OpenFaxFile()) == NULL) {
  64.         err = PDERR_BUFFERMEMORY;
  65.         break;
  66.     }
  67.     LineBufSize = (XSize + 7) / 8;
  68.     TotalBufSize = PED->ped_NumRows * LineBufSize;
  69.     PD->pd_PrintBuf = AllocMem(TotalBufSize, MEMF_PUBLIC);
  70.     if (PD->pd_PrintBuf == NULL) {
  71.         faxout_close(FaxHandle);
  72.         FaxHandle = NULL;
  73.         err = PDERR_BUFFERMEMORY;
  74.         break;
  75.     }
  76.     faxout_begin_page(FaxHandle, PED->ped_YDotsInch > Y_DPI/2);
  77.     break;
  78.     case 1: /* Scale, Dither and Render */
  79.         /*
  80.          *        ct        - pointer to PrtInfo structure.
  81.          *        x        - 0.
  82.          *        y        - row # (0 to Height - 1).
  83.          */
  84. #define pi ((struct PrtInfo *)ct)
  85.     if (pi->pi_xpos >= XSize) {
  86.         debug(("Invalid pi_xpos %d (%x)\n", pi->pi_xpos, pi->pi_xpos));
  87.         pi->pi_xpos = 0;
  88.     }
  89.     Transfer((struct PrtInfo *)ct, y, PD->pd_PrintBuf + LineBufSize * (y % PED->ped_NumRows));
  90.     break;
  91.     case 2: /* Dump Buffer to Printer */
  92.     /*
  93.      *    ct    - 0.
  94.      *    x    - 0.
  95.      *    y    - # of rows sent (1 to ped_NumRows).
  96.      */
  97.     {
  98.         int         offset;
  99.  
  100.         debug(("Call tofax %dx\n", y));
  101.         for (offset = 0; y > 0; offset += LineBufSize, y--) {
  102.         tofax(FaxHandle, PD->pd_PrintBuf + offset, XSize);
  103.         }
  104.     }
  105.     break;
  106.     case 3:    /* Clear and Init Buffer */
  107.     /*
  108.      *    ct    - 0.
  109.      *    x    - 0.
  110.      *    y    - 0.
  111.      */
  112.     memset(PD->pd_PrintBuf, 0, TotalBufSize);
  113.     break;
  114.     case 4: /* Close Down */
  115.     /*
  116.      *    ct    - error code.
  117.      *    x    - io_Special flag from IODRPReq.
  118.      *    y    - 0.
  119.      */
  120.  
  121.     debug(("Close down\n"));
  122.     if (FaxHandle) {
  123.         faxout_end_page(FaxHandle);
  124.         faxout_close(FaxHandle);
  125.         FaxHandle = NULL;
  126.     }
  127.     if (PD->pd_PrintBuf != NULL) {
  128.         FreeMem(PD->pd_PrintBuf, TotalBufSize);
  129.         PD->pd_PrintBuf = NULL;
  130.     }
  131.     break;
  132. #ifdef DEBUG
  133.     default:
  134.     debug(("!!Render ct %08lx x %d y %d status %d\n", ct, x, y, status));
  135.     break;
  136. #endif
  137.     }
  138.     return(err);
  139. }
  140.  
  141. #include <clib/asl_protos.h>
  142.  
  143. void *
  144. OpenFaxFile(void)
  145. {
  146.     char       *filename = NULL;
  147.  
  148.     if (AslBase && FileReq) {
  149.     if (AslRequest(FileReq, NULL)) {
  150.         static char     fn[128];
  151.         int         len;
  152.  
  153.         strcpy(fn, FileReq->rf_Dir);
  154.         len = strlen(fn);
  155.         if (len > 0 && fn[len-1] != ':')
  156.         strcat(fn, "/");
  157.         strcat(fn, FileReq->rf_File);
  158.         filename = fn;
  159.     }
  160.     } else {
  161.     filename = "FAX:faxrastportdump";
  162.     }
  163.  
  164.     if (filename)
  165.     return faxout_open(filename, 1 + NoFormFeed);
  166.     return NULL;
  167. }
  168.